#include <cpr/cpr.h>
#include <iostream>
#include <nlohmann/json.hpp>

// https://github.com/nlohmann/json
int main() {
    nlohmann::json json_data = {
            {"appName",     "wechat-clean"},
            {"versionCode", 1}
    };

    std::string json_string = json_data.dump();

    cpr::Response r = cpr::Get(
            cpr::Url{"https://n-backend.cupb.top/api/v1/application"},
            cpr::Header{
                    {"Content-Type",    "application/json"},
                    {"User-Agent",      "IntelliJ HTTP Client/GoLand 2024.1.4"},
                    {"Accept-Encoding", "br, deflate, gzip, x-gzip"},
                    {"Accept",          "*/*"},
                    {"content-length",  std::to_string(json_string.length())}
            },
            cpr::Body{json_string}
    );


    if (r.status_code == 200) {
        nlohmann::json response_json = nlohmann::json::parse(r.text);

        if (response_json["code"] == 200) {
            nlohmann::json data = response_json["data"];
            bool enable = data["enable"];
            if (enable) {
                std::cout << "app enable" << std::endl;
            } else {
                std::cout << "disable" << std::endl;
                std::exit(0);
            }
        } else {
            std::cerr << "code != 200" << response_json["message"] << std::endl;
        }
    } else {
        std::cerr << "Failed to send request" << r.status_code << std::endl;
    }
    return 0;
}